#include <gtest/gtest.h>


#include "memdb/memdb.h"
#include "memdb/impl/mock/MockDB.h"
#include "memdb/impl/mock/MockTables.h"
#include "memdb/impl/mock/MockTable.h"

using namespace memdb;
using namespace impl;
using namespace mock;
TEST(MemdbTest, testDB){
	MockDB db;
  if(db.open().isOK()){

		auto & tables = db.tables();
		ASSERT_FALSE(tables.drop("table_1"));

		{ //create success
			auto r = tables.create("table_1");
			ASSERT_TRUE(r.first);
			r.second->insert("key", "value");
		}

		{ //table already exist
			auto r = tables.create("table_1");
			ASSERT_FALSE(r.first);
			r.first.inspectError([](const auto & e) {
				std::cerr << "DBError:" << (int)e << std::endl;
			});
		}

		auto tab_get = tables.get("table_1");
		ASSERT_TRUE(tab_get);
		tab_get.value()->insert("key", "value");


		db.close();
	}
	db.destroy();
}



TEST(DBResultTest, test){
	std::cout << memdb::DBResult::OK() << std::endl;
	std::cout << memdb::DBResult::OK().okInfo(memdb::DBError::Error) << std::endl;


	std::cout << memdb::DBResult::Error(memdb::DBError::TableNotExist) << std::endl;
	std::cout << memdb::DBResult::Error((memdb::DBError)-100) << std::endl;
	std::cout << memdb::DBResult::Error((memdb::DBError)0) << std::endl;
	std::cout << memdb::DBResult::Error((memdb::DBError::MaxErrorCode)) << std::endl;
	std::cout << memdb::DBResult::Error((memdb::DBError)100) << std::endl;
}

